//Flies down in a curve and drops bullets.

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Birds1.png");
let SEshotm5=("script\SoundEffects\shotm5.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=4;
let scale=1;
let enemycolor=160;
let shots=0;
let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let color=GetArgument[1];

let starty=GetY;
let angle=0;
if(startx<cx){ angle=160+rand_int(0,5); }
if(startx>cx){ angle=20+rand_int(0,5); }

@Initialize{
	LoadGraphic("\script\Images\Enemies\Birds1.png");
	LoadSE("script\SoundEffects\shotm5.wav");

	SetInvincibility(20);
	SetLife(5);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);


if(GetCommonData("Difficulty")==1){
	if(frame%8==0){
	CreateShot02(GetX,GetY,0,90+rand(-4,4),0.015,rand(2,2.5),36+color,0);
	}
	if(frame%10==0){ PlaySE(SEshotm5); }
} //Easy

//=========================================================================================================

if(GetCommonData("Difficulty")==2){
	if(frame%5==0){
	CreateShot02(GetX,GetY,0,90+rand(-6,6),0.015,rand(2.5,3),36+color,0);
	}
	if(frame%5==0){ PlaySE(SEshotm5); }
} // Normal

//=========================================================================================================

if(GetCommonData("Difficulty")==3){
	if(frame%3==0){
	CreateShot02(GetX,GetY,0,90+rand(-8,8),0.015,rand(3,3.5),36+color,0);
	}
	if(frame%5==0){ PlaySE(SEshotm5); }
} // Hard

//=========================================================================================================

if(GetCommonData("Difficulty")==4){
	if(frame%3==0){
	CreateShot02(GetX,GetY,0,90+rand(-10,10),0.015,rand(3,4),36+color,0);
	}
	if(frame%5==0){ PlaySE(SEshotm5); }
} // Lunatic
} // OnScreen

oldX=GetX;
oldY=GetY;
SetX(cx+300*cos(angle));
SetY(miny-150+starty+200*sin(angle));
let speed=0.75;
if(GetCommonData("Difficulty")==3){ speed=1; }
if(startx<cx){ angle-=speed; }
if(startx>cx){ angle+=speed; }


frame++;
time++;
//animation++;
if(animation>=ani*4){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
let side=0;
	SetTexture(GRenemy);
		if(oldX<GetX || oldX>GetX){ side=128; }
		if(animation>=ani*0 && animation<ani*1){ SetGraphicRect(0,enemycolor,80,80+enemycolor); }
		if(animation>=ani*1 && animation<ani*2){ SetGraphicRect(80,enemycolor,160,80+enemycolor); }
		if(animation>=ani*2 && animation<ani*3){ SetGraphicRect(160,enemycolor,240,80+enemycolor); }
		if(animation>=ani*3 && animation<ani*4){ SetGraphicRect(80,enemycolor,160,80+enemycolor); }
	SetAngle(atan2(GetY-oldY,GetX-oldX));
	SetGraphicAngle(0,0,GetAngle+180);
	if(oldX<GetX){ SetGraphicAngle(180,0,-GetAngle); }
	SetGraphicScale(scale,scale);
	SetColor(255-invincible,255-invincible,255);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	loop(2){ CreateEnemyFromFile("script\Functions\itemscore.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0);
	CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0);

	if(GetCommonData("Difficulty")==2){
	let angle=GetAngleToPlayer;
		loop(5){
		CreateShot02(GetX,GetY,0,angle,0.05,3,60+color,0);
		angle+=360/5;
		}
	}
	if(GetCommonData("Difficulty")==3){
	let angle=GetAngleToPlayer;
		loop(7){
		CreateShot02(GetX,GetY,0,angle,0.05,3.5,60+color,0);
		angle+=360/7;
		}
	}
	if(GetCommonData("Difficulty")==4){
	let angle=GetAngleToPlayer;
		loop(10){
		CreateShot02(GetX,GetY,0,angle,0.1,4,60+color,0);
		angle+=360/10;
		}
	}
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}